function [quality] = sensingQuality(A,Ap)
% Function to computed the sensing quality function:
% F(A) = var(Xv) - integral[P(Xa=xa)*var(Xv|Xa=xa)dxa
% outputs:  quality            - the computed sensing quality
% inputs:   A               - the data set associated with those nodes currently included in the set
%           Ap              - the data set associated with those nodes not currently included in the set (stands for Aprime)
% Note:     Data set A and Ap have nodes in the columns and time steps in the rows

    % need to know how many nodes are in A and Ap
    V = [A Ap];
    [nT,nV] = size(V);

    % this function evaluates the equation for F(A) = 1/|V| * sum (all s in V) [ sigma(sA) * sigma(AA)^-1 * sigma(As) ]
    quality = 0;
    for i=1:nV
    
        % compute the total covariance matrix for each element in V compared to A
        totalCov = cov([V(:,i) A]);
    
        % grab the different parts of the covariance matrix
        % first row is sigma(s,A)
        SA = totalCov(1,2:end);
        % first column is sigma(A,s)
        AS = totalCov(2:end,1);
        % remaining row and column block is sigma(A,A)
        AA = totalCov(2:end,2:end);
    
        % accumulate the quality for all nodes in V
        quality = quality + (SA / AA * AS);
    end
    quality = quality ./ nV;
end
